package com.aly.beanValidate.core;

import com.aly.game.util.StringUtils;
import org.dom4j.Attribute;
import org.dom4j.Element;

public class Util {
    public static String attr(Element element, String attName, String dft) {
        if (element == null) {
            return dft;
        }
        Attribute attribute = element.attribute(attName);
        if (attribute == null) {
            return dft;
        }
        return attribute.getValue() == null ? dft : attribute.getValue();
    }

    public static String attr(Element element, String attName) {
        String attr = attr(element, attName, "");
        if (StringUtils.isEmpty(attr)) {
            throw new RuntimeException(element + "--> 需要配置 att:" + attName);
        }
        return attr;
    }
}
